package com.client.controller;

import com.Emplyment.entity.Article;
import com.Emplyment.entity.CompanyCollect;
import com.Emplyment.result.Result;
import com.Emplyment.vo.CategoriesVo;
import com.client.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/company")
@Slf4j
public class ComponyController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/categories")
    public Result<List<CategoriesVo>> getCategories() {
        //获取公司分类
        List<CategoriesVo> categoriesVo = companyService.getCategories();
        log.info("categoriesVo:{}", categoriesVo);
        return Result.success(categoriesVo);
    }

    @GetMapping
    public Result<List<Article>> getCompany(@RequestParam("categoryId") Integer categoryId) {
        //根据条件获取公司数据
        log.info("公司分类id:{}", categoryId);
        List<Article> company = companyService.getCompany(categoryId);
        log.info("获取到的公司数据为:{}", company);
        return Result.success(company);
    }

    @PostMapping("/collect")
    @Transactional
    public Result collect(@RequestBody CompanyCollect collect) {
        //收藏公司
        log.info("收藏公司信息的数据:{}", collect);
        companyService.collect(collect);
        return Result.success();
    }

    @PostMapping("/canceCollect")
    @Transactional
    public Result canceCollect(@RequestBody CompanyCollect collect) {
        //取消收藏公司
        log.info("取消收藏公司信息的数据:{}", collect);
        companyService.canceCollect(collect);
        return Result.success();
    }

    @PostMapping("/status")
    public Result<Integer> getCompanyStatus(@RequestBody CompanyCollect collect) {
        log.info("获取公司收藏状态：{}",collect);
        //获取公司是否收藏状态
        Integer companyStatus = companyService.getCompanyStatus(collect);
        log.info("companyStatus:{}", companyStatus);
        return Result.success(companyStatus);
    }

    @GetMapping("/searchcompany")
    public Result<List<Article>> searchCompany( @RequestParam("keyword") String keyword) {
        log.info("搜索的关键词：{}",keyword);
        List<Article> list = companyService.searchCompany(keyword);
        log.info("搜索的公司信息：{}",list);
        return Result.success(list);
    }

}
